<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }
    #application {
      text-align: center;
    }
    .btn {
      margin-left: 10px;
      cursor: pointer;
    }
  </style>
</head>
<body>
  <div id="application">
    <h1>Todo List</h1>
    <div>
      <span>新建任务：</span>
      <input type="text" placeholder="请输入任务..." v-model="taskText">
      <button class="btn" @click="addTask">添加</button>
    </div>
    <ul>
      <li v-for="(task, index) in taskList" :key="task.id">
        <span>{{task.taskText}}</span>
        <button @click="removeTask(index)">删除任务</button>
      </li>
    </ul>
  </div>
  <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
  <script>
    const App = {
      data() {
        return {
          taskText: '',
          taskList: []
        }
      },
      methods: {
        addTask() {
          if (!this.taskText) {
            alert('请输入任务内容')
            return
          }
          this.taskList.push({
            id: Date.now(),
            taskText: this.taskText
          })
        },
        removeTask(index) {
          this.taskList.splice(index, 1)
        }
      }
    }
    Vue.createApp(App).mount('#application')
  </script>
</body>
</html>